<script type="text/javascript">
    function clearPrice(obj){
        nocheckname = obj.val();
        $("input[name='"+nocheckname+"']").val("");
    }
</script>
<form class="layui-form layui-box modal-form-box" action="{:request()->url()}" data-auto="true" method="post">


    <div class="layui-form-item">
        <div class="layui-form-item">
            <label class="layui-form-label">地区：</label>
            <div class="layui-input-inline">
                <select name="area" id="area" lay-verify="required" class="layui-input" style="display: block; width: 300px;">
                    <option value="">请选择地区</option>
                    {foreach $areas as $area }
                    <option value="{$area.id}" {if $area.id == $area_id} selected="selected" {/if}>{$area.area_name}</option>
                    {/foreach}

                </select>
            </div>
        </div>
    </div>






    <div class="layui-form-item">
        <blockquote class="layui-elem-quote">请勾选此地区支持的洗衣类型，并且输入相对应的价格（单位：元/次）</blockquote>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <div class="layui-input-inline">
                <input type="checkbox" name="type[]" {if condition="in_array(1,array_keys($price))"}  checked="checked" {/if} onclick="clearPrice($(this))"  value="1" title="标准洗"><span style="padding-left: 5px;">标准洗</span>
            </div>
            <div class="layui-input-inline">
                <input type="text" name="1" value="{if condition='in_array(1,array_keys($price))'}{$price[1]}{/if}" class="layui-input">
            </div>
        </div>
        <div class="hr-line-dashed"></div>
        <div class="layui-input-block">
            <div class="layui-input-inline">
                <input type="checkbox" name="type[]" value="2"  {if condition="in_array(2,array_keys($price))"}  checked="checked" {/if} onclick="clearPrice($(this))"  title="快速洗"><span style="padding-left: 5px;">快速洗</span>
            </div>
            <div class="layui-input-inline">
                <input type="text" name="2" value="{if condition='in_array(2,array_keys($price))'}{$price[2]}{/if}"  class="layui-input">
            </div>
        </div>
        <div class="hr-line-dashed"></div>
        <div class="layui-input-block">
            <div class="layui-input-inline">
                <input type="checkbox" name="type[]" value="3" {if condition="in_array(3,array_keys($price))"}  checked="checked" {/if} onclick="clearPrice($(this))" title="单脱水"><span style="padding-left: 5px;">单脱水</span>
            </div>
            <div class="layui-input-inline">
                <input type="text" name="3"  value="{if condition='in_array(3,array_keys($price))'}{$price[3]}{/if}" class="layui-input">
            </div>
        </div>
        <div class="hr-line-dashed"></div>
        <div class="layui-input-block">
            <div class="layui-input-inline">
                <input type="checkbox" name="type[]" {if condition="in_array(4,array_keys($price))"}  checked="checked" {/if}  onclick="clearPrice($(this))"  value="4" title="大物洗"><span style="padding-left: 5px;">大物洗</span>
            </div>
            <div class="layui-input-inline">
                <input type="text" name="4" value="{if condition='in_array(4,array_keys($price))'}{$price[4]}{/if}"  class="layui-input">
            </div>
        </div>

    <div class="hr-line-dashed"></div>

    <div class="layui-form-item text-center">
        {if isset($vo['id'])}<input type='hidden' value='{$vo.id}' name='id'>{/if}
        {if isset($edit)}<input type="hidden" name="edit" value="true">{/if}
        <button class="layui-btn" id="submit" type='submit'>保存数据</button>
        <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗？" data-close>取消编辑</button>
    </div>


</form>


<script type="text/javascript">
    $("#submit").click(
        function () {
            //校验地区
            area = parseInt($("#area").val());
            if(!area){
                layer.msg('请选择正确的地区', {icon: 2});
                return false;
            }
            //校验洗衣类型和价格
            types = $("input[name='type[]']");
            typesArray = [];
            types.each(function (i,key) {
                if ($(this).is(':checked')) {
                    typesArray.push($(this).val());
                }else{
                    nocheckname = $(this).val();
                    $("input[name='"+nocheckname+"']").val("");
                }
            });
            if(typesArray.length <1){
                layer.msg('请勾选洗衣类型以及对应的价格', {icon: 2});
                return false;
            }
            var result = true;
            $.each(typesArray,function (index,value) {
                if(value == 1 && $("input[name='1']").val()<=0 ){  //标准洗
                    layer.msg('标准洗价格填写错误', {icon: 2});
                    result = false;
                    return false;
                }
                if(value == 2 && $("input[name='2']").val()<=0 ){  //快洗
                    layer.msg('快洗价格填写错误', {icon: 2});
                    result = false;
                    return false;
                }
                if(value == 3 && $("input[name='3']").val()<=0 ){  //单脱
                    layer.msg('单脱价格填写错误', {icon: 2});
                    result = false;
                    return false;
                }
                if(value == 4 && $("input[name='4']").val()<=0 ){  //大物件洗
                    layer.msg('大物件洗价格填写错误', {icon: 2});
                    result = false;
                    return false;
                }
            })
            if (!result)  return false;
        }
    );
</script>